// 1-提示信息
function __showMessage(content, callback, type) {
    if (!type) {
        type = "success";
    }
    var timer = 2000;
    var n = noty({
        type : type,
        modal : true,
        timeout : timer,
        text : content + '(' + (timer / 1000) + 's)',
        callback : {
            afterClose : function() {
                if (callback) {
                    callback();
                }
            }
        }
    });
    setInterval(function() {
        timer -= 1000;
        n.setText(content + "(" + (timer / 1000) + "s)");
    }, 1000);
}

// 2-确认信息
function __showConfirm(content, callback, yes, no) {
    yes = yes || "是";
    no = no || "不是";
    noty({
        modal : true,
        type : 'warning',
        text : content,
        buttons : [
            {
                addClass : 'btn btn-success',
                text : '<span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;'+ yes,
                onClick : function($noty) {
                    $noty.close();
                    if (callback) {
                        callback();
                    }
                }
            },{
                addClass : 'btn btn-danger',
                text : '<span class="glyphicon glyphicon-thumbs-down"></span>&nbsp;' + no,
                onClick : function($noty) {
                    $noty.close();
                }
            }
        ]
    });
}

// 3-确认信息
function __makeChoice(content, yes, no, auto) {
    var yesTitle = "是";
    if (yes && yes.title) {
        yesTitle = yes.title;
    }
    var noTitle = "不是";
    if (no && no.title) {
        noTitle = no.title;
    }

    var t = undefined;
    var n = noty({
        modal : true,
        type : 'warning',
        text : content,
        buttons : [
            {
                addClass : 'btn btn-success',
                text : '<span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;' + yesTitle,
                onClick : function($noty) {
                    if (t) {
                        clearInterval(t);
                    }
                    $noty.close();
                    if (yes && yes.callback) {
                        yes.callback();
                    }
                }
            },{
                addClass : 'btn btn-danger',
                text : '<span class="glyphicon glyphicon-thumbs-down"></span>&nbsp;'
                        + noTitle,
                onClick : function($noty) {
                    if (t) {
                        clearInterval(t);
                    }
                    $noty.close();
                    if (no && no.callback) {
                        no.callback();
                    }
                }
            }
        ]
    });
    if (auto && auto.timer != undefined && auto.timer > 0) {
        var timer = auto.timer;
        n.setText(content + "(" + (timer / 1000) + "s)");
        t = setInterval(function() {
            timer -= 1000;
            if (timer < 0) {
                clearInterval(t);
                n.close();
                if (auto && auto.callback) {
                    auto.callback();
                }
            } else {
                n.setText(content + "(" + (timer / 1000) + "s)");
            }
        }, 1000);
    }
}

// 5-弹出层
function __showDialog(url, title, width, height, callBack_onClose) {
    var id = $.mothin.util.newGuid();
    var s = '<div id="div_' + id + '" style="';
    if (!width || !height) {
        width = 800;
        height = 600;
    }
    s += 'width:' + width + 'px;';
    s += 'height:' + height + 'px;';
    s += '"><iframe id="iframe_' + id + '" frameborder="0" width="100%" height="100%"></iframe></div>';
    $(s).window({
        width : width,
        height : height,
        title : title,
        modal : true,
        minimizable : false,
        onBeforeClose : function() {
            if (callBack_onClose) {
                callBack_onClose();
            }
        },
        onClose : function() {
            $("#div_" + id).dialog("destroy");
        }
    });
    $("#iframe_" + id).attr("src", url);
}

// 6-打开操作界面
function openTab(title, url,canNotClosable) {
    var tab = $('#main_frame').tabs('getTab', title);  // get selected panel
    if(tab) {
        var tabSelected = $('#main_frame').tabs('getSelected');
        if(tabSelected!=tab){
            var closable=tab.panel('options').closable;
            $('#main_frame').tabs('select', title);
            $('#main_frame').tabs('update', {
                tab: tab,
                options: {
                    title: title,
                    content: '<div style="height: 100%;"><iframe height="100%" width="100%" border="0" frameborder="0" align="top" src="'+url+'"></iframe></div>',
                    // iconCls:iconCls?iconCls:'',
                    closable: closable
                }
            });
        }
    }else{
        var closable=true;
        if(canNotClosable){
            closable=false;
        }
        $('#main_frame').tabs('add', {
            title: title,
            content: '<div style="height: 100%;"><iframe height="100%" width="100%" border="0" frameborder="0" align="top" src="'+url+'"></iframe></div>',
            // iconCls:iconCls?iconCls:'',
            closable: closable
        });
    }
}
